sky.define('i4/dialog',['./widget/kite'],function(require,dialog){
	dialog.version = '1.0.0';
	//kite
	var kite = require(0);
	var m1 = new kite.Mask(null,.4,1000000);

	//销毁弹窗
	function destroy(){
		this.destroy();
	}

	var opt_default = {
		title_text:'提示信息',
		context:'信息内容'
	};

	function getOptContent(str,df){
		var opt = sky.extra(opt_default,df || {},{});
		if(typeof str == 'string'){
			opt.context = str;
		}
		else{
			opt = sky.extra(str,opt);
		}
		return opt;
	}

	function replaceText(str,opt){
		return str.replace(/\{#(\w+)\}/g,function($0,$1){
			return opt[$1] || '';
		});
	}

	//============ 自定义 弹窗  =====================
	var string_prompt = [
		'<div class="c_opt {#opt_class}"><div class="re_c">',
			'<span class="close" sky-kite="close">×</span>',
			'<div class="ttt" sky-kite="title">{#title_text}</div>',
			'<div class="ccc" sky-kite="con">',
				'{#context}',
			'</div>',
			'<div class="btns" sky-kite="btns">',
				'{#buttons}',
			'</div>',
		'</div></div>'
	].join('');

	function prompt(str,opt,focus){
		return m1.create(replaceText(str,opt),focus).offset(.5,.5).bind('close',destroy).drag('title');
	}

	dialog.prompt = function(str,buttons){
		return prompt(string_prompt,getOptContent(str,{buttons:buttons || ''}));
	};

	//============alert 弹窗 ========================
	var string_alert = string_prompt.replace(/\{\#buttons\}/g,'<span class="d_btn_1" sky-kite="btn_ok">{#btn_ok_text}</span>');
	dialog.alert = function(str,fn){
		return prompt(
			string_alert,
			getOptContent(str,{btn_ok_text:'确认',opt_class:'c_opt_alert'}),
			'btn_ok'
		).bind('btn_ok_vclick',fn || destroy);
	};

	//============confiorm 弹窗 ========================
	var string_confiorm = string_prompt.replace(/\{\#buttons\}/g,'<span class="d_btn_2" sky-kite="btn_cancel">{#btn_cancel_text}</span>&nbsp;&nbsp;<span class="d_btn_1" sky-kite="btn_ok">{#btn_ok_text}</span>');
	dialog.confirm = function(str,fn,fn1){

		return prompt(
			string_confiorm,
			getOptContent(str,{btn_ok_text:'确认',btn_cancel_text:'取消',opt_class:'c_opt_confirm'}),
			'btn_ok'
		).bind('btn_ok_vclick',fn || destroy).bind('btn_cancel_vclick',fn1 || destroy);
	};
});